<?php
// TODO: dodawanie, edytowanie, usuwanie vortal
session_start();
class Controller_Admin_ReviewRequest extends Controller_Admin_Abstract
{
	public function __construct(Controller_Front $frontController)
	{
		parent::__construct('admin_reviewrequest', $frontController);
	}	
	
	public function indexAction()
	{
		$this->view()->display('admin_reviewrequest.tpl');
	}
	
	public function newAction()
	{
		$reviewrequest;
		$buttonName;
		
		if (isset($_GET['id_review_request'])) {
			$id = $_GET['id_review_request'];
			$buttonName = 'Edytuj';
			
			$reviewrequest = ReviewRequestsPeer::retrieveByPK($id);
		} else {
			$buttonName = 'Dodaj';
			$reviewrequest = new Reviewrequests();
		}
		$this->view()->assign('reviewrequest', $reviewrequest);
		$this->view()->assign('editButton', $buttonName);
		$_SESSION['enable']=true;
		$this->view()->display('admin_reviewrequest_edit.tpl');
	}
	
	public function listAction()
	{
		$reviewrequest = ReviewRequestsPeer::doSelect(new Criteria());
		$this->view()->assign('reviewrequest', $reviewrequest);
		
		$this->view()->display('admin_reviewrequest_list.tpl');
	}
	
	public function checkAction()
	{		
		$vortals;
		
		if (!empty($_POST['id_review_request'])) {
			$id = $_POST['id_review_request'];
			
			$reviewrequest = ReviewRequestsPeer::retrieveByPK($id);
		} else {
			$reviewrequest = new Reviewrequests();
		}
		
		if($_SESSION["enable"]==true) {
			$reviewrequest->setDescription($_POST['description']);
			$reviewrequest->setIdUser(Manager_User::getUser()->getIdUser());
			$reviewrequest->setIdRequestStatus('1');
			$reviewrequest->save();
			$this->ok('Review Request description was added and is awaiting for develop.');
			$_SESSION['enable']=false;			
		} else {
			$this->fail('Review Request description was not added and is awaiting for develop.');
		}
	}	
	
	public function deleteAction()
	{
		
		if (!isset($_GET['id_review_request'])) {
			throw new Exception('id not spec');
		}	
		
		$id = $_GET['id_review_request'];
		try {
			ReviewRequestsPeer::doDelete($id);
			$this->ok('Review Request delete.');
		} catch (Exception $e) {
			$this->view()->assign('fail_info', 'Nie uda�o si� usun�� ' 
				. $e->getMessage());  	
			return $this->view()->display('fail.tpl');		
		}
				
			
	}
	
}